package com.behelpful.demo.gateway.config;

import com.behelpful.demo.gateway.handler.SwaggerResourceHandler;
import com.behelpful.demo.gateway.handler.SwaggerSecurityHandler;
import com.behelpful.demo.gateway.handler.SwaggerUiHandler;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * 设置路由程序类,已过时,可是用 WebFlux 方式
 *
 * @author Alay
 * @date 2021-09-05 23:28
 * @see com.behelpful.demo.gateway.action.SwaggerResourceAction
 * @since
 */
@Deprecated(since = "SwaggerResourceAction")
@Configuration
@AllArgsConstructor
public class RouterFunctionConfig {
    /**
     * 聚合各个服务的swagger接口
     */
    private final SwaggerResourceHandler swaggerResourceHandler;
    /**
     * 权限处理器
     */
    private final SwaggerSecurityHandler swaggerSecurityHandler;
    /**
     * UI处理器
     */
    private final SwaggerUiHandler swaggerUiHandler;


    @Bean
    public RouterFunction<ServerResponse> routerFunction() {
        return RouterFunctions
                .route(RequestPredicates.GET("/swagger-resources")
                        .and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler)
                .andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
                        .and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler)
                .andRoute(RequestPredicates.GET("/swagger-resources/configuration/security")
                        .and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler);
    }
}
